//
// Created by Tunm-Air13 on 2024/3/15.
//

#ifndef SIMPLESEMANTIC_TEXT_PROCESSING_H
#define SIMPLESEMANTIC_TEXT_PROCESSING_H

#include <iostream>
#include <string>
#include <regex>
#include <vector>
#include <algorithm>

namespace solex {

// Extract an integer number from a string
inline std::vector<int> ExtractNumbers(const std::string& str, bool isDescending = false) {
    std::vector<int> numbers;
    std::regex regex("\\d+");
    auto begin = std::sregex_iterator(str.begin(), str.end(), regex);
    auto end = std::sregex_iterator();

    for (std::sregex_iterator i = begin; i != end; ++i) {
        std::smatch match = *i;
        numbers.push_back(std::stoi(match.str()));
    }

    if (isDescending) {
        std::sort(numbers.begin(), numbers.end(), std::greater<int>());
    }

    return numbers;
}

// Extract integer numbers from some array string
inline std::vector<int> ExtractAndSortNumbers(const std::vector<std::string>& words, bool isDescending = false) {
    std::vector<int> numbers;
    std::regex regex("^\\d+$");

    for (const auto& word : words) {
        if (std::regex_match(word, regex)) {
            numbers.push_back(std::stoi(word));
        }
    }

    if (isDescending) {
        std::sort(numbers.begin(), numbers.end(), std::greater<int>());
    } else {

    }

    return numbers;
}


}   // namespace solex

#endif //SIMPLESEMANTIC_TEXT_PROCESSING_H
